var tailClue = function() {
    var self = this;
    self.lastTime = 0;
};
tailClue.prototype = {};

tailClue.prototype.init = function() {
    var self = this;
    self.restore();

    // 定期拉取数据
    setInterval(function() {
        self.loop();
    }, 15 * 1000);
}

tailClue.prototype.loop = function() {
    var self = this;
    CMD.user_online_query({
        tail: 1,
        time: self.lastTime,
    }, function(r) {
        for (var i in r.list) {
            alert(r.list[i].user.mobile + "上线了，请关注！");
        }
    });
    self.lastTime = get_server_time() * 1000;
    self.save();
}

tailClue.prototype.restore = function() {
    var self = this;
    try {
        if (localStorage) {
            var v = localStorage.getItem("com.cp-zy-tail");
            if (v) self.lastTime = parseInt(v);
        }
    }
    catch(e) {
        console.error(e);
    }
}

tailClue.prototype.save = function() {
    var self = this;
    try {
        if (localStorage) localStorage.setItem("com.cp-zy-balance", self.lastTime);
    }
    catch(e) {
        console.error(e);
    }
}

window.TailClue = new tailClue();